package
{
	import flash.globalization.NumberFormatter;
	

	public class Utils
	{
		public static function toRGB(color:uint):String{
			var s:String = toHex((color>>16)&0xFF) + toHex((color>>8)&0xFF) + toHex((color)&0xFF);
			return s;
		}
		
		public static function toARGB(color:uint, alpha:Number):String{
			var s:String = toHex(alpha * 255) + toHex((color>>16)&0xFF) + toHex((color>>8)&0xFF) + toHex((color)&0xFF);
			return s;
		}
		
		public static function toHex(value:Number):String
		{
			if ( isNaN(value) )
				return "00";
			
			value = Math.round(Math.max(Math.min(value, 255), 0));
			
			var mask:String = "0123456789ABCDEF";
			
			var pos1:Number = (value-(value%16))/16;
			var pos2:Number = value%16;
			
			return mask.charAt(pos1) + mask.charAt(pos2);
		}
		
		public static function formatNumber(n:Number):String{
			var formatter:NumberFormatter = new NumberFormatter('en_us');
			formatter.trailingZeros = false;
			return formatter.formatNumber(n);
		}
	}
}